package internationalenergytradingplatform.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import internationalenergytradingplatform.context.BaseContext;
import internationalenergytradingplatform.dao.CommodityMapper;
import internationalenergytradingplatform.dto.CommodityPageQueryDTO;
import internationalenergytradingplatform.pojo.Commodity;
import internationalenergytradingplatform.pojo.Employee;
import internationalenergytradingplatform.result.PageResult;
import internationalenergytradingplatform.service.SupplierCommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SupplierCommodityServiceImpl implements SupplierCommodityService {

    @Autowired
    CommodityMapper commodityMapper;
    /**
     *
     * @author yingfeng
     * @date 2024/3/4 21:44
   分页查询
     */
    public PageResult pageQuery(CommodityPageQueryDTO commodityPageQueryDTO) {
        //开始分页查询
        String companyId = BaseContext.getCurrentId();//获取公司id
        commodityPageQueryDTO.setSupplierAccount(companyId);
        PageHelper.startPage(commodityPageQueryDTO.getPage(), commodityPageQueryDTO.getPageSize());
        Page<Commodity> page = commodityMapper.CommodityPageQuery(commodityPageQueryDTO);
        long total = page.getTotal();
        List<Commodity> records = page.getResult();
        return new PageResult(total, records);
    }
}
